<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\validate;

use app\lib\exception\OrderException;

/**
 * 订单参数验证
 * Class OrderValidate
 * @package app\api\validate
 */
class OrderValidate extends BaseValidate
{
    protected $rule = [
        ['mobile', 'require|isMobile', '请输入手机号|手机号格式不正确'],
        ['subscribe_date', 'require|isNotEmpty|compareTime', '请选择预约时间|预约时间不能为空|预约时间必须大于当前时间'],
        ['driving_license_id', 'require|isNotEmpty', '请选择行驶证|行驶证不能为空'],
    ];

    /**
     * @Desc 预约时间是否正确
     *
     * @param string $value 字段值
     *
     * @return bool true|false
     */
    protected function compareTime($value)
    {
        if (strtotime($value) < strtotime(date("y-m-d"))) {
            throw new OrderException([
                'code'      => 400,
                'message'   => '预约时间必须大于当前时间',
                'errorCode' => 40004,
            ]);
        }
        return true;
    }
}